package cn.tedu.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * JDBC执行查询语句[DQL]
 * 查询所以用户名的密码，用户名，年龄
 */
public class JDBCDemo5 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();) {
            Statement statement = connection.createStatement();
            String sql ="SELECT userName,passWord,age FROM userinfo";
            ResultSet resultSet = statement.executeQuery(sql);
            while(resultSet.next()){
                String userName = resultSet.getString("userName");
                String passWord = resultSet.getString("passWord");
                int age = resultSet.getInt("age");
                System.out.println(userName+","+passWord+","+age);

            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
